<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="en" name="language">
	<title>GraphicsMagick Wand C API</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link media="screen" href="../docutils-articles.css" type="text/css" rel="stylesheet">

</head>

<body>

<div class="banner">
<img src="../images/gm-107x76.png" alt="GraphicMagick logo" width="107" height="76" />
<span class="title">GraphicsMagick</span>
<form action="http://www.google.com/search">
  <input type="hidden" name="domains" value="www.graphicsmagick.org" />
  <input type="hidden" name="sitesearch" value="www.graphicsmagick.org" />
<span class="nowrap"><input type="text" name="q" size="25" maxlength="255" />&nbsp;<input type="submit" name="sa" value="Search" /></span>
</form>
</div>


<div class="navmenu">
<ul>
  <li><a href="../index.html">Home</a></li>
  <li><a href="../project.html">Project</a></li>
  <li><a href="../download.html">Download</a></li>
  <li><a href="../README.html">Install</a></li>
  <li><a href="../Hg.html">Source</a></li>
  <li><a href="../NEWS.html">News</a> </li>
  <li><a href="../utilities.html">Utilities</a></li>
  <li><a href="../programming.html">Programming</a></li>
  <li><a href="../reference.html">Reference</a></li>
</ul>
</div>

<main id="graphicsmagick-wand-c-api">
<h1 class="title">GraphicsMagick Wand C API</h1>
<!-- -*- mode: rst -*- -->
<!-- This text is in reStucturedText format, so it may look a bit odd. -->
<!-- See http://docutils.sourceforge.net/rst.html for details. -->
<p>The GraphicsMagick Wand C library provides a mid-level abstract C
language programming interface for GraphicsMagick.  It is originally
based on the Wand API provided in ImageMagick as of August 2003.
After August 2003, ImageMagick changed its license to one unusable by
GraphicsMagick so this version of the Wand library is not completely
in sync with the current ImageMagick version.</p>
<p>The API is divided into a number of categories. While reading this
documentation, please reference the <a class="reference external" href="../api/types.html">types</a> documentation as required:</p>
<blockquote>
<ul class="simple">
<li><p><a class="reference external" href="drawing_wand.html">Drawing</a>: Wand vector drawing interfaces.</p></li>
<li><p><a class="reference external" href="magick_wand.html">Magick</a>: Wand image processing interfaces</p></li>
<li><p><a class="reference external" href="pixel_wand.html">Pixel</a>: Wand pixel access/update interfaces</p></li>
</ul>
</blockquote>
<p>The following is a simple example program which (assuming the program
name is <cite>rotate</cite>) is executed similar to <cite>rotate infile outfile</cite>.  It
reads from file <cite>infile</cite>, rotates the image 30 degrees using a black
background, and writes the result to file <cite>outfile</cite>:</p>
<pre class="literal-block">#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;wand/magick_wand.h&gt;

int main(int argc,char **argv)
{
  MagickWand *magick_wand;
  MagickPassFail status = MagickPass;
  const char *infile, *outfile;

  if (argc != 3)
    {
      fprintf(stderr,&quot;Usage: %s: infile outfile\n&quot;,argv[0]);
      return 1;
    }

  infile=argv[1];
  outfile=argv[2];

  // Initialize GraphicsMagick API
  InitializeMagick(*argv);

  // Allocate Wand handle
  magick_wand=NewMagickWand();

  // Read input image file
  if (status == MagickPass)
    {
      status = MagickReadImage(magick_wand,infile);
    }

  // Rotate image clockwise 30 degrees with black background
  if (status == MagickPass)
    {
      PixelWand *background;
      background=NewPixelWand();
      PixelSetColor(background,&quot;#000000&quot;);
      status = MagickRotateImage(magick_wand,background,30);
      DestroyPixelWand(background);
    }

  // Write output file
  if (status == MagickPass)
    {
      status = MagickWriteImage(magick_wand,outfile);
    }

  // Diagnose any error
  if (status != MagickPass)
    {
      char *description;
      ExceptionType severity;

      description=MagickGetException(magick_wand,&amp;severity);
      (void) fprintf(stderr,&quot;%.1024s (severity %d)\n&quot;,
                     description,severity);
    }

  // Release Wand handle
  DestroyMagickWand(magick_wand);

  // Destroy GraphicsMagick API
  DestroyMagick();

  return (status == MagickPass ? 0 : 1);
}</pre>
<p>To compile on Unix, the command looks something like this:</p>
<pre class="literal-block">gcc -o demo demo.c -O `GraphicsMagickWand-config --cppflags --ldflags --libs`</pre>
<p>The GraphicsMagickWand-config script reproduces the options which were used to
compile the GraphicsMagick wand library. Using compatible options ensures that
your program will compile and run.</p>
</main>


<hr class="docutils">
<div class="document">
    <p><a href="../Copyright.html">Copyright</a> © GraphicsMagick Group 2002-2025<!--SPONSOR_LOGO--></p>
</div>

</main>
</body>
</html>
